#ifndef CAPTURESERVER_H
#define CAPTURESERVER_H

#include <QObject>
#include <QTimer>
#include <QWindow>
#include "qavcodeccontext.h"
#include "capture/capturefactory.h"

struct SwsContext;

class CaptureServer : public QObject
{
    Q_OBJECT
public:
    explicit CaptureServer(int id, QObject *parent = nullptr);
    virtual ~CaptureServer();
    ScreenCapture* window();
    void startMs(std::chrono::milliseconds msec);
    void requestOneKeyFrame();
private:
    void initEncoder();

signals:
    void outputStream(const QByteArray &data);
public slots:
    void start();
    void stop();
private:
    void taskShot();
private:
    ScreenCapture *m_window;
    QAVCodecContext *m_ctx;
    SwsContext *m_sws;
    QTimer m_timer;
    int m_pts;
    QByteArray m_md5;
    bool m_keyFrame;
};

#endif // CAPTURESERVER_H
